package com.github.live.adapter;

import android.annotation.SuppressLint;
import android.graphics.Color;
import android.widget.TextView;
import com.github.live.R;
import com.github.livebase.bean.ChannelGroup;


/**
 * @author pj567
 * @date :2021/1/12
 * @description:
 */
public class LiveChannelGroupAdapter extends SimpleRecyclerAdapter<ChannelGroup> {
    private int selectedGroupIndex = -1;
    private int focusedGroupIndex = -1;

    @SuppressLint("ResourceType")
    public LiveChannelGroupAdapter() {
        super(R.layout.item_live_channel_group);
    }

    public void setSelectedGroupIndex(int selectedGroupIndex) {
        if (selectedGroupIndex == this.selectedGroupIndex) return;
        int preSelectedGroupIndex = this.selectedGroupIndex;
        this.selectedGroupIndex = selectedGroupIndex;
        if (preSelectedGroupIndex != -1)
            notifyItemChanged(preSelectedGroupIndex);
        if (this.selectedGroupIndex != -1)
            notifyItemChanged(this.selectedGroupIndex);
    }

    public int getSelectedGroupIndex() {
        return selectedGroupIndex;
    }

    public void setFocusedGroupIndex(int focusedGroupIndex) {
        this.focusedGroupIndex = focusedGroupIndex;
        if (this.focusedGroupIndex != -1)
            notifyItemChanged(this.focusedGroupIndex);
        else if (this.selectedGroupIndex != -1)
            notifyItemChanged(this.selectedGroupIndex);
    }

    @Override
    void onBindViewHolder(SimpleViewHolder holder, ChannelGroup data, int position) {
        TextView tvGroupName = holder.findViewById(R.id.tvChannelGroupName);
        tvGroupName.setText(data.getName());
        if (position == selectedGroupIndex && position != focusedGroupIndex) {
            tvGroupName.setTextColor(mContext.getResources().getColor(R.color.color_theme));
        } else {
            tvGroupName.setTextColor(Color.WHITE);
        }
    }
}